package com.example.springbootdemo.bean;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Lazy;

@Slf4j
@Data
@ConfigurationProperties(prefix = "java")
public class Bean4 implements Inter, ApplicationContextAware {
  private String home;
  private String version;

  public Bean4() {
    log.debug("constructor bean4");
  }

  //  @Lazy
  @Autowired
  private BeanForPrototype beanForPrototype;

  @Lazy
  @Autowired
  private BeanForPrototype2 beanForPrototype2;

  @Autowired
  private BeanForPrototype3 beanForPrototype3;

  @Autowired
  private ObjectFactory<BeanForPrototype4> beanForPrototype4;

  public BeanForPrototype4 getBeanForPrototype4(){
    return beanForPrototype4.getObject();
  }

  @Override
  public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
    this.applicationContext = applicationContext;
  }

  private ApplicationContext applicationContext;

  public BeanForPrototype5 getBeanForPrototype5(){
    return applicationContext.getBean(BeanForPrototype5.class);
  }
}
